package com.example.fw;

import com.example.tests.ContactData;

public class ContactsHelper extends HelperBase{

	public ContactsHelper(AppManager manager) {
		super(manager);
	}

    public void createContact(ContactData contact) {
        initContactCreation();
        fillContactsForms(contact);
        confirmContactCreation();
    }

    public ContactData getFirstContact() {
        manager.getAutoItHelper()
                .winWaitAndActivate("AddressBook Portable", "", 5000)
                .click("TListView1")
                .send("{DOWN}{SPACE}")
                .click("Edit")
                .winWaitAndActivate("Update Contact", "", 5000);
        ContactData contact = new ContactData()
                .withFirstname(manager.getAutoItHelper().getText("TDBEdit12"))
                .withLastname(manager.getAutoItHelper().getText("TDBEdit11"));
        manager.getAutoItHelper()
                .click("Cancel")
                .winWaitAndActivate("AddressBook Portable", "", 5000);
        return contact;
    }
    // -----------------------------------------------------------------------------------------------

    private void confirmContactCreation() {
        manager.getAutoItHelper()
                .click("Save")
                .winWaitAndActivate("AddressBook Portable", "", 5000);
    }

    private void fillContactsForms(ContactData contact) {
        manager.getAutoItHelper()
                .send("TDBEdit12", contact.getFirstname())
                .send("TDBEdit11", contact.getLastname());
    }

    private void initContactCreation() {
        manager.getAutoItHelper()
                .winWaitAndActivate(manager.getProps().getProperty("winTitle"), "", 5000) // я дебажился на другой программе, поэтому такое определение
                .click("Add").winWaitAndActivate("Add Contact", "", 5000);
    }
}